package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/5/2 18:58
 */
public class C165 {


    public static int compareVersion(String version1, String version2) {
        String[] str1 = version1.split("\\.");
        String[] str2 = version2.split("\\.");
        int len = Math.max(str1.length, str2.length);
        for (int i = 0; i < len; i++) {
            int p1 = i < str1.length ? Integer.parseInt(str1[i]) : 0;
            int p2 = i < str2.length ? Integer.parseInt(str2[i]) : 0;
            if(p1 != p2){
                return p1 > p2 ? 1 : -1;
            }
        }
        return 0;
    }


    // for test
    public static void main(String[] args) {
        String v1 = "7.5.2.4";
        String v2 = "7.5.3";
        System.out.println(compareVersion(v1, v2));
    }

}
